﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace CourierManager
{
    public class Driver : Employee, ISalary 
    {
        public string DriverRoute { get; set; }
        public int RoutesCount { get; set; }
        public bool IsOnACourse { get; set; }
        
        public Driver(string firstName, string lastName, string address, ulong idNumber, ulong phone, decimal salary, bool isOnACourse=false) 
            : base(firstName, lastName, address, idNumber, phone, salary)
        {
            this.IsOnACourse = isOnACourse;
        }

        public Driver():this(null, null, null, 0,0,0)
        {
        }

        public decimal CalculateSalary()
        {
            decimal salary = this.Salary;
            if (RoutesCount >= 30)
            {
                salary += 250;
            }

            return salary;
        }

        public override void SaveEmployeeData()
        {
            StreamWriter writer = new StreamWriter(this.PathToDataBase, true);
            //string type = Convert.ToString(this);
            using (writer)
            {
                Type classType = this.GetType();
                string employee = String.Format("{0}*{1}*{2}*{3}*{4}*{5}*{6}*{7}", classType.Name, this.FirstName, this.LastName,
                    this.Address, this.IDNumber, this.Phone, this.Salary,this.IsOnACourse);
                writer.WriteLine(employee);
            }
        }
    }
}
